package pkg

import (
	"fmt"

	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

var MysqlDB *gorm.DB

func init() {
	// 数据库连接信息
	// 测试环境
	// username := "zhike"
	// password := "Azhike8@"
	// host := "rm-8vbfr8v4lh1n92ax8mo.mysql.zhangbei.rds.aliyuncs.com"

	// 压测环境
	username := "mixinim"
	password := "Amixinim8@"
	host := "rm-8vb89b0njl61z3f8n8o.mysql.zhangbei.rds.aliyuncs.com"

	port := "3306"
	// database := "im3_dev"
	database := "im3_dev1"

	// 构建连接字符串
	dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s", username, password, host, port, database)

	// 建立连接
	db, err := gorm.Open(mysql.New(mysql.Config{
		DSN:               dataSource,
		DefaultStringSize: 256,
	}), &gorm.Config{
		DisableAutomaticPing: false,
		NowFunc:              nil,
		//禁用软删除查询限制
		// DisableForeignKeyConstraintWhenMigrating: true,
		// IgnoreRelationshipsWhenMigrating: true,
	})
	if err != nil {
		fmt.Println(err)
		return
	}

	MysqlDB = db
}
